﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TelnetRouterApplication.Control;

namespace TelnetRouterApplication.View
{
    public partial class CommandListPanel : UserControl
    {
        public CommandListPanel()
        {
            InitializeComponent();
        }

        private void searchButton_Click(object sender, EventArgs e)
        {
            try
            {
                searchButton.Enabled = false;
                if (rbRoot.Checked)
                {
                    RouterLevelHandler.GetInstance().GoTo(RouterLevelHandler.Location.connected);
                }
                else if (rbEnable.Checked)
                {
                    RouterLevelHandler.GetInstance().GoTo(RouterLevelHandler.Location.enabled);
                }
                else if (rbConfig.Checked)
                {
                    RouterLevelHandler.GetInstance().GoTo(RouterLevelHandler.Location.config);
                }

                string command = tbCommand.Text;
                ConnectionHandler.GetInstance().SendMessageNoEnter(command + " ?");
                string result = "Erro ocorreu.";
                try
                {
                    result = ConnectionHandler.GetInstance().ReceiveMessageWithNoSpaces();
                }
                catch (Exception ex)
                {
                }
                cbResult.Clear();
                string commandToClear = "";
                for (int i = 0; i < command.Length; i++)
                {
                    commandToClear += "\\8";
                }
                ConnectionHandler.GetInstance().SendMessageNoEnter(commandToClear);
                
                cbResult.AppendText(result);
            }
            finally
            {
                searchButton.Enabled = true;
            }
        }

    }
}
